﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using csRebides;
using Mono.Data.Sqlite; 


namespace csRebides
{

    class csRebides
    {
        functions function;

        public csRebides()
        {
            //TODO your code here
            this.function = new functions();
        }

        static void Main(string[] args)
        {
            DateTime startTime = DateTime.Now;

            System.IO.StreamWriter file = new System.IO.StreamWriter("rebidesFile.txt");

            System.IO.StreamWriter timeFile = new System.IO.StreamWriter("timeFile.txt");

            csRebides csR = new csRebides();

            csR.sTeacherYear(file);

            csR.sTeacherEstY(file);

            csR.sTeacherDegY(file);

            csR.TeacherDegEstY(file);

            csR.sTeatcherDocDegY(file);

            csR.sSetTeacherDocDegEstY(file);

            csR.lEstYear(file);

            csR.lHolYear(file);

            csR.listTeachChanEY(file);

            csR.listTeachLeavingEY(file);

            csR.listTeachNewEY(file);

            /*csR.sTeacherMigYear(file);*/

            csR.sTeacherPromEstY(file);

            file.Close();

            DateTime endTime = DateTime.Now;
            TimeSpan totalTime = endTime - startTime;

            timeFile.WriteLine("#############################################");
            timeFile.WriteLine("Total runing time in minutes: " + totalTime.TotalMinutes);
            timeFile.WriteLine("#############################################");

            timeFile.Close();
        }


        /* »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
         * here start the methods of this class
         * »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
        */

        /*
         * ##########################################################################
         * calls function
         * print and write the statistic with the number of teachers per year
         * ##########################################################################
         */
        void sTeacherYear(System.IO.StreamWriter file)
        {
            Dictionary<string, int> statTY = function.statTeachY();
            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 1");
            file.WriteLine("#############################################");
            file.WriteLine("#Statistic whit number of teachers pear year#");
            file.WriteLine("#############################################");

            foreach (KeyValuePair<string, int> kvp in statTY)
            {
                //Console.WriteLine(kvp.Key + kvp.Value);
                file.WriteLine(kvp.Key + kvp.Value);
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } //end of sTeacherYear



        /*
         * #########################################################################################
         * calls function
         * print and write the statistic with the number of teachers per establishemt and year
         * #########################################################################################
         */
        void sTeacherEstY(System.IO.StreamWriter file)
        {
            Dictionary<string, Dictionary<string, int>> statTEY = function.statTeachEstY();
            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 2");
            file.WriteLine("################################################################");
            file.WriteLine("#Statistic whit number of teachers pear establishment pear year#");
            file.WriteLine("################################################################");

            foreach (KeyValuePair<string, Dictionary<string, int>> kvp in statTEY)
            {
                //Console.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine();
                file.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                Dictionary<string, int> ndic = statTEY[kvp.Key];

                foreach (KeyValuePair<string, int> kvp1 in ndic)
                {
                    //Console.WriteLine(kvp1.Key + ndic[kvp1.Key]);
                    file.WriteLine(kvp1.Key + ndic[kvp1.Key]);
                }
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } // end of sTeacherEstY



        /*
         * #########################################################################################
         * calls function
         * print and write the statistic with the number of teachers per degree and year
         * #########################################################################################
         */
        void sTeacherDegY(System.IO.StreamWriter file)
        {
            Dictionary<string, Dictionary<string, int>> statTDY = function.statTeachDegY();
            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 3");
            file.WriteLine("################################################################");
            file.WriteLine("#Statistic whit number of teachers pear degree pear year       #");
            file.WriteLine("################################################################");

            foreach (KeyValuePair<string, Dictionary<string, int>> kvp in statTDY)
            {
                //Console.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine();
                file.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                Dictionary<string, int> ndic = statTDY[kvp.Key];

                foreach (KeyValuePair<string, int> kvp1 in ndic)
                {
                    //Console.WriteLine(kvp1.Key + ndic[kvp1.Key]);
                    file.WriteLine(kvp1.Key + ndic[kvp1.Key]);
                }
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } //end of sTeacherDegY



        /*
         * ############################################################################################################
         * calls function
         * print and write the statistic with the number of teachers per degree per establishemt and year
         * ############################################################################################################
         */
        void TeacherDegEstY(System.IO.StreamWriter file)
        {
            Dictionary<string, Dictionary<string, Dictionary<string, int>>> statTDEY = function.statTeachDegEstY();

            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 4");
            file.WriteLine("#####################################################################################");
            file.WriteLine("#Statistic whit number of teachers pear degree and pear establishment and pear year #");
            file.WriteLine("#####################################################################################");

            foreach (KeyValuePair<string, Dictionary<string, Dictionary<string, int>>> kvp in statTDEY)
            {
                //Console.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine();
                file.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                Dictionary<string, Dictionary<string, int>> degDic = statTDEY[kvp.Key];

                foreach (KeyValuePair<string, Dictionary<string, int>> kvp1 in degDic)
                {
                    file.WriteLine();
                    file.WriteLine("Printing " + kvp1.Key + " statistics");
                    file.WriteLine("------------------------------------");
                    file.WriteLine();

                    Dictionary<string, int> estDic = degDic[kvp1.Key];

                    foreach (KeyValuePair<string, int> kvp2 in estDic)
                    {
                        Console.WriteLine(kvp2.Key + estDic[kvp2.Key]);
                        file.WriteLine(kvp2.Key + estDic[kvp2.Key]);
                    }
                }
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } //end of TeacherDegEstY



        /*
         * #############################################################################################################
         * calls function
         * print and write the statistic with the number of teachers with doctorate degree per establishemt and year
         * #############################################################################################################
         */
        void sTeatcherDocDegY(System.IO.StreamWriter file)
        {
            Dictionary<string, Dictionary<string, Dictionary<string, int>>> statTDocDEY = function.statTeachDocDegEstY();

            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 5");
            file.WriteLine("##########################################################");
            file.WriteLine("#Statistic whit number of teachers with Doctorate degree #");
            file.WriteLine("#pear establishment and pear year                        #");
            file.WriteLine("##########################################################");

            foreach (KeyValuePair<string, Dictionary<string, Dictionary<string, int>>> kvp in statTDocDEY)
            {
                //Console.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine();
                file.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                Dictionary<string, Dictionary<string, int>> docDegDic = statTDocDEY[kvp.Key];

                foreach (KeyValuePair<string, Dictionary<string, int>> kvp1 in docDegDic)
                {
                    file.WriteLine();
                    file.WriteLine("Printing " + kvp1.Key + " statistics");
                    file.WriteLine();

                    Dictionary<string, int> estDic = docDegDic[kvp1.Key];

                    foreach (KeyValuePair<string, int> kvp2 in estDic)
                    {
                        //Console.WriteLine(kvp2.Key + estDic[kvp2.Key]);
                        file.WriteLine(kvp2.Key + estDic[kvp2.Key]);
                    }
                }
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } // end of sTeatcherDocDegY



        /*
         * #############################################################################################################
         * calls function
         * print and write the statistic with the set of teachers with doctorate degree per establishemt and year
         * #############################################################################################################
         */
        void sSetTeacherDocDegEstY(System.IO.StreamWriter file)
        {
            Dictionary<string, Dictionary<string, List<string>>> statSetTDocEY = function.statSetTeachDocDegEstY();

            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 6");
            file.WriteLine("##########################################################");
            file.WriteLine("#Statistic whit set of teachers with Doctorate degree    #");
            file.WriteLine("#pear establishment and pear year                        #");
            file.WriteLine("##########################################################");

            foreach (KeyValuePair<string, Dictionary<string, List<string>>> kvp in statSetTDocEY)
            {
                //Console.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine();
                file.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                Dictionary<string, List<string>> docDegDic = statSetTDocEY[kvp.Key];

                foreach (KeyValuePair<string, List<string>> kvp1 in docDegDic)
                {
                    file.WriteLine();
                    file.WriteLine("Printing " + kvp1.Key + " statistics");
                    file.WriteLine("------------------------------------");
                    file.WriteLine();

                    List<string> estDic = docDegDic[kvp1.Key];

                    foreach (string techName in estDic)
                    {
                        //Console.WriteLine(techName);
                        file.WriteLine(techName);
                    }
                }
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } // end of sTeatcherDocDegY



        /*
         * #############################################################################################################
         * calls function
         * print and write the list of teachers who changed from establishment
         * #############################################################################################################
         */
        void listTeachChanEY(System.IO.StreamWriter file)
        {
            Dictionary<string, Dictionary<List<string>, int>> lTeachChanEstY = function.statSetTeachChangeEstY();
            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 7");
            file.WriteLine("##################################################");
            file.WriteLine("#List of teachers who changed from establishment #");
            file.WriteLine("##################################################");

            foreach (KeyValuePair<string, Dictionary<List<string>, int>> kvp0 in lTeachChanEstY)
            {
                Dictionary<List<string>, int> dicT = kvp0.Value;

                foreach (KeyValuePair<List<string>, int> kvp in dicT)
                {
                    List<string> teachList = kvp.Key; 
                    //Console.WriteLine("Printing list of: " + kvp.Key);
                    file.WriteLine();
                    file.WriteLine("Printing list of: " + kvp0.Key);
                    file.WriteLine("----------------------------------");
                    file.WriteLine();

                    foreach (string teachName in teachList)
                    {
                        //Console.WriteLine(teachName);
                        file.WriteLine(teachName);
                    }
                    file.WriteLine();
                    file.WriteLine("Nº of teachers migrating in the " + kvp0.Key +": " + kvp.Value);
                }
                
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } // end of listTeachChanEY



        /*
         * ##########################################################################
         * calls function
         * print and write the list of estabelishments per year
         * ##########################################################################
         */
        void lEstYear(System.IO.StreamWriter file)
        {
            Dictionary<string, List<string>> lEstabY = function.listEstabY();
            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 8");
            file.WriteLine("#############################################");
            file.WriteLine("#List of establishments pear year           #");
            file.WriteLine("#############################################");

            foreach (KeyValuePair<string, List<string>> kvp in lEstabY)
            {
                List<string> estabList = kvp.Value;
                //Console.WriteLine("Printing list of: " + kvp.Key);
                file.WriteLine();
                file.WriteLine("Printing list of: " + kvp.Key);
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                foreach (string estabName in estabList)
                {
                    //Console.WriteLine(estabName);
                    file.WriteLine(estabName);
                }
                
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } // end of lEstYear



        /*
         * ##########################################################################
         * calls function
         * print and write the list of estabelishments per year
         * ##########################################################################
         */
        void lHolYear(System.IO.StreamWriter file)
        {
            Dictionary<string, List<string>> lHoldY = function.listHolDY();
            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 9");
            file.WriteLine("#############################################");
            file.WriteLine("#List of teachers pear year                 #");
            file.WriteLine("#############################################");

            foreach (KeyValuePair<string, List<string>> kvp in lHoldY)
            {
                List<string> estabList = kvp.Value;
                //Console.WriteLine("Printing list of: " + kvp.Key);
                file.WriteLine();
                file.WriteLine("Printing list of: " + kvp.Key);
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                foreach (string teachName in estabList)
                {
                    //Console.WriteLine(teachName);
                    file.WriteLine(teachName);
                }

            }
            //Console.WriteLine("End");
            file.WriteLine();
        } //end of lHolYear


        
        /*
         * #############################################################################################################
         * calls function
         * print and write the list with the number of teachers leaving establishments per year
         * #############################################################################################################
         */
        void listTeachLeavingEY(System.IO.StreamWriter file)
        {
            Dictionary<string, Dictionary<string, int>> listTeachLeavEY = function.listTeachLeavEY();

            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 10");
            file.WriteLine("##########################################################");
            file.WriteLine("#List whit number of teachers leaving                    #");
            file.WriteLine("#an establishment in one year                            #");
            file.WriteLine("##########################################################");

            foreach (KeyValuePair<string, Dictionary<string, int>> kvp in listTeachLeavEY)
            {
                //Console.WriteLine("Printing " + kvp.Key + " statistics");
                //Console.WriteLine();
                file.WriteLine();
                file.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                Dictionary<string, int> teachEstab = listTeachLeavEY[kvp.Key];

                foreach (KeyValuePair<string, int> kvp1 in teachEstab)
                {
                    //Console.WriteLine(kvp1.Key + ": " + teachEstab[kvp1.Key]);
                    file.WriteLine(kvp1.Key + ": " + teachEstab[kvp1.Key]);
                }
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } // end of listTeachLeavingEY


        /*
         * #############################################################################################################
         * calls function
         * print and write the list with the number of new teachers per establishments and year
         * #############################################################################################################
         */
        void listTeachNewEY(System.IO.StreamWriter file)
        {
            Dictionary<string, Dictionary<string, int>> listTeachNewEY = function.listTeachNewEY();

            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 11");
            file.WriteLine("##########################################################");
            file.WriteLine("#List whit number of new teachers                        #");
            file.WriteLine("#per establishment in one year                           #");
            file.WriteLine("##########################################################");

            foreach (KeyValuePair<string, Dictionary<string, int>> kvp in listTeachNewEY)
            {
                //Console.WriteLine("Printing " + kvp.Key + " statistics");
                //Console.WriteLine();
                file.WriteLine();
                file.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                Dictionary<string, int> teachEstab = kvp.Value;

                foreach (KeyValuePair<string, int> kvp1 in teachEstab)
                {
                    //Console.WriteLine(kvp1.Key + ": " + kvp1.Value);
                    file.WriteLine(kvp1.Key + ": " + kvp1.Value);
                }
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } // end of listTeachLeavingEY



        /*
         * ##########################################################################
         * calls function
         * print and write the statistic with the number of teachers per year
         * ##########################################################################
         */
        void sTeacherMigYear(System.IO.StreamWriter file)
        {
            Dictionary<string, int> statTY = function.statTeachMigratingY();
            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 12");
            file.WriteLine("################################################");
            file.WriteLine("#Statistic whit number of teachers migrating   #");
            file.WriteLine("#from one establishment to another one by year #");
            file.WriteLine("################################################");

            foreach (KeyValuePair<string, int> kvp in statTY)
            {
                //Console.WriteLine(kvp.Key + ": " + kvp.Value);
                file.WriteLine();
                file.WriteLine(kvp.Key + ": " + kvp.Value);
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } //end of sTeacherMigYear



        /*
         * #########################################################################################
         * calls function
         * print and write the statistic with the number of teachers per establishemt and year
         * #########################################################################################
         */
        void sTeacherPromEstY(System.IO.StreamWriter file)
        {
            Dictionary<string, Dictionary<string, int>> statTPEY = function.statTeachPromEstY();
            //Console.WriteLine();
            //Console.WriteLine("Printing the Dictionary 13");
            file.WriteLine("#####################################################################");
            file.WriteLine("#Statistic whit number of teachers promoted pear establishment/year #");
            file.WriteLine("#####################################################################");

            foreach (KeyValuePair<string, Dictionary<string, int>> kvp in statTPEY)
            {
                //Console.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine();
                file.WriteLine("Printing " + kvp.Key + " statistics");
                file.WriteLine("-----------------------------------");
                file.WriteLine();

                Dictionary<string, int> ndic = statTPEY[kvp.Key];

                foreach (KeyValuePair<string, int> kvp1 in ndic)
                {
                    //Console.WriteLine(kvp1.Key + ndic[kvp1.Key]);
                    file.WriteLine(kvp1.Key + ": " + ndic[kvp1.Key]);
                }
            }
            //Console.WriteLine("End");
            file.WriteLine();
        } // end of sTeacherPromEstY

    }//end of class csRebides

} //end of namespace
